new Vue({
  el: '#app',
  data() {
    return {
      html: '',
      options: [{
        value: 0,
        label: '协议管理'
        // }, {
        //     value: 1,
        //     label: '行情描述'
        // }, {
        //     value: 2,
        //     label: '国内资讯'
        // }, {
        //     value: 3,
        //     label: '国际资讯'
        // }, {
        //     value: 4,
        //     label: '公司动态'
        //
      }
      ],
      form: {
        User_Agreement_SerialNumber: "",
        User_Agreement_Title: '',
        User_Agreement_Main: "",
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
      },
      loading: false
    }
  },
  mounted() {
    let User_Agreement_SerialNumber = window.sessionStorage.getItem('User_Agreement_SerialNumber')
    this.SeeDetail(User_Agreement_SerialNumber)
    this.getNews()
  },
  methods: {
    SeeDetail(User_Agreement_SerialNumber) {
      console.log(1);
      const _this = this
      let data = {
        Primary_Key_Name: 'User_Agreement_SerialNumber',
        Primary_Key: User_Agreement_SerialNumber,
        Data: 'user_agreement',
      }
      $.ajax({
        url: DomainName + '/getInquiryIDOriginal?token=' + $.cookie("token"),
        type: 'POST',
        data,
        success: function (res) {
          // console.log(res);
          _this.form = res[0];
          _this.html = res[0].User_Agreement_Main
          // this,html = res[0].
          console.log(_this.form);
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },
    getNews() {
      const { createEditor, createToolbar } = window.wangEditor
      const this_ = this
      const editorConfig = {
        placeholder: '新闻内容',
        onChange(editor) {
          console.log(editor);
          this_.html = editor.getHtml()
          console.log(this_.html)
          // this_.form.User_Agreement_Main = editor.getHtml()
          // that.$emit('change', that.form.User_Agreement_Main)
          // 也可以同步到 <textarea>
        }
      }
      const editor = createEditor({
        selector: '#editor-container',
        html: this.form.User_Agreement_Main,
        config: editorConfig,
        mode: 'simple', // or 'simple'

      })

      editor.dangerouslyInsertHtml(this_.html)

      const toolbarConfig = {}

      const toolbar = createToolbar({
        editor,
        selector: '#toolbar-container',
        config: toolbarConfig,
        mode: 'default', // or 'simple'
      })
      // editor.txt.html(this.form.User_Agreement_Main)
    },
    back() {
      window.history.go(-1)
    },
    subMessage() {
      this.form.User_Agreement_Main = this.html
      const _this = this;
      _this.loading = true;
      console.log(this.form);
      let data = {
        Data: JSON.stringify({
          Modify: { user_agreement: [this.form] }
        })
      };
      $.ajax({
        url: DomainName + '/getEditAction?token=' + $.cookie('token'),
        type: 'POST',
        data,
        success: function (res) {
          console.log('提交结果', res)
          if (res.Status == 'success') {
            _this.$message.success("发布成功!")
            window.history.go(-1)
          }
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  },
})